// index.js
// 在小程序的页面 js 文件中
Page({
  data: {
    bottomNavList: [{
      url: '#',
      onthis: true,
      img: '../../images/tab_icon_home_on.png',
      title: '投票'
    },{
      url: '../lottery/lottery',
      img: '../../images/tab_icon_gift.png',
      title: '抽奖'
    },{
      url: '../intro/intro',
      img: '../../images/tab_icon_comment.png',
      title: '大赛简介'
    },{
      url: '../rank/rank',
      img: '../../images/tab_icon_list.png',
      title: '排行榜'
    }],
    dataList: [{
      data: 18167,
      text: '参与数'
    },{
      data: 98291,
      text: '投票数'
    },{
      data: 24877,
      text: '访问量'
    }],
    timer: '00 天 00 时 00 分 00 秒',
    productList: [{
      id: 0,
      img: '../../images/product_list_img_demo.jpg',
      name: '量产型全自动探针台A系列量产型全自动探针台A系列',
      vote: '98665'
    },{
      id: 1,
      img: '../../images/product_list_img_demo.jpg',
      name: '量产型全自动探针台A系列',
      vote: '98665'
    },{
      id: 2,
      img: '../../images/product_list_img_demo.jpg',
      name: '量产型全自动探',
      vote: '98665'
    },{
      id: 3,
      img: '../../images/product_list_img_demo.jpg',
      name: '量产型全自动探针台A系列',
      vote: '98665'
    }]
  },

  onLoad() {
    this.startCountdown();
  },

  startCountdown() {
    // 使用数字
    const targetDate = new Date(2026, 3, 7, 10, 0, 0);
    
    const updateCountdown = () => {
      const now = new Date();
      const timeDifference = targetDate - now;
      
      if (timeDifference <= 0) {
        this.setData({
          countdownText: '倒计时已结束！'
        });
        return;
      }
      
      const days = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
      const hours = Math.floor((timeDifference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
      const minutes = Math.floor((timeDifference % (1000 * 60 * 60)) / (1000 * 60));
      const seconds = Math.floor((timeDifference % (1000 * 60)) / 1000);
      
      this.setData({
        timer: `${days} 天 ${hours} 时 ${minutes} 分 ${seconds} 秒`
      });
    };
    
    // 立即执行一次
    updateCountdown();
    
    // 每秒更新
    this.countdownTimer = setInterval(updateCountdown, 1000);
  },

  onUnload() {
    // 页面卸载时清除定时器
    if (this.countdownTimer) {
      clearInterval(this.countdownTimer);
    }
  }
});
